package com.geostar.gmp.global;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.geostar.gmp.exception.ElementException;
import com.geostar.gmp.utils.ReadXMLUtils;


/**
 * 文件名:GetOidList.java
 * 功能: 加载/mibconfig.xml文件的OID值，并保存在List集合中
 * 目前支持方法
 * --------------------------------------
 * 初始版本 
 * 作者: yesong
 * 时间: Apr 1, 2014
 */
public class GetOidForList {
	
	private static Logger LOGGER = LoggerFactory.getLogger(GetOidForList.class);
	private static List<String> OidList;

	public static List<String> getOidList() {
		return OidList;
	}
	
	public static void load(){
		ReadXMLUtils.loadXML(ConfigValue.MIBCONFIG_XML);
		try {
			List<Element> elist = ReadXMLUtils.readElementsByNode(ConfigValue.PATH_OID);
			if(elist==null || elist.size()==0){
				LOGGER.info("OID集合为空或集合长度为0");
			}
			OidList = Element2OidList(elist);
		} catch (ElementException e) {
			e.printStackTrace();
		}
	}
	
	public static void reload(){
		clear();
		load();
	}
	
	private static void clear(){
		OidList = null;
	}
	
	private static List<String> Element2OidList(List<Element> elist){
		List<String> oidList = new ArrayList<String>();
		for (Element element : elist) {
			oidList.add(element.elementTextTrim("oid"));
		}
		return oidList;
	}
}
